package com.wyp.didishige.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.wyp.didishige.R;
import com.wyp.didishige.utils.ImageLoadOptions;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.datatype.BmobFile;

/**
 * 用户图片
 * Created by horry on 2015/4/24.
 */
public class UserImageAdapter extends BaseAdapter {
    protected Context mContext;
    protected LayoutInflater mInflater;
    protected List<BmobFile> mDatas = new ArrayList<BmobFile>();

    public UserImageAdapter(Context context, List<BmobFile> datas) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        if (datas != null && datas.size() > 0) {
            mDatas = datas;
        }
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_face_text, null);
            holder = new ViewHolder();
            holder.mIvImage = (ImageView) convertView
                    .findViewById(R.id.v_face_text);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BmobFile image = (BmobFile) getItem(position);

        ImageLoader.getInstance().displayImage(image.getUrl(), holder.mIvImage, ImageLoadOptions.getOptions());
        return convertView;
    }

    class ViewHolder {
        ImageView mIvImage;
    }
}
